package com.hxy.treeview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.jingzhi.mindmap.view.RightTreeLayoutManager;
import com.jingzhi.mindmap.view.TreeView;
import com.jingzhi.mindmap.model.NodeModel;
import com.jingzhi.mindmap.model.TreeModel;
import com.jingzhi.mindmap.util.DensityUtils;
import com.jingzhi.mindmap.view.TreeViewItemClick;

public class MainActivity extends AppCompatActivity {

    private TreeView treeView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();

    }

    private void initView(){
        treeView = findViewById(R.id.my_tree_view);
    }

    private void initData(){
        final NodeModel<String> nodeA = new NodeModel<>("pos");
        final NodeModel<String> nodeB = new NodeModel<>("impose");
        final NodeModel<String> nodeC = new NodeModel<>("expose");
        final NodeModel<String> nodeD = new NodeModel<>("oppose");
        final NodeModel<String> nodeE = new NodeModel<>("depose");
        final NodeModel<String> nodeF = new NodeModel<>("suppose");
        final NodeModel<String> nodeG = new NodeModel<>("扩展词汇");
        final NodeModel<String> nodeH = new NodeModel<>("扩展词汇");


        final TreeModel<String> tree = new TreeModel<>(nodeA);
        tree.addNode(nodeA, nodeB, nodeC, nodeD,nodeE,nodeF);
        tree.addNode(nodeC);
        tree.addNode(nodeB,nodeG,nodeH);
        tree.addNode(nodeD);

        int dx = DensityUtils.dp2px(getApplicationContext(), 30);
        int dy = DensityUtils.dp2px(getApplicationContext(), 30);
        int screenHeight = DensityUtils.dp2px(getApplicationContext(), 720);
        treeView.setTreeLayoutManager(new RightTreeLayoutManager(dx, dy, screenHeight));
        treeView.setTreeModel(tree);
        
        treeView.setTreeViewItemClick(new TreeViewItemClick() {

            @Override
            public void onItemClick(View item, String content) {
                Toast.makeText(MainActivity.this, "跳转到单词："+content+"的详情页", Toast.LENGTH_SHORT).show();
            }
        });
    }
}